rm(list= ls())

library(tidyverse)
library(lfe)

## Load Election Data

dat <- readRDS('data/fed_elections_kreise.rds') %>%
  filter(year >= 1961) %>% 
  filter(year <= 1965)  %>%  
  mutate(post = ifelse(year >= 1965, 1, 0)) %>%
  mutate(treated_post = n_syn_bin * post) %>%
  mutate(treated = n_syn_bin) %>%
  mutate(year = as.character(year))

## Define outcomes 

outcomevars <- c('fdp',
                 'far_right_vs_excl_dp',
                 'cdu_csu',
                 'spd')

m1 <- as.formula(paste('fdp', 'treated_post | county_id_1950 + year | 0 | county_id_1950', sep = '~'))
m2 <- as.formula(paste('far_right_vs_excl_dp', 'treated_post | county_id_1950 + year | 0 | county_id_1950', sep = '~'))
m3 <- as.formula(paste('cdu_csu', 'treated_post | county_id_1950 + year | 0 | county_id_1950', sep = '~'))
m4 <- as.formula(paste('spd', 'treated_post | county_id_1950 + year | 0 | county_id_1950', sep = '~'))

mlist <- lapply(list(m1, m2, m3, m4), function(m){
  
  felm(m, data = dat)
  
})


stargazer::stargazer(mlist, 
                     style  = 'ajps',
                     keep = c('treated_post'))



